package xyz.fuqufyb.aec.controller;

import com.github.pagehelper.PageInfo;
import com.spingcloud.travel.common.CommonConst;
import com.spingcloud.travel.common.JsonResult;
import com.spingcloud.travel.common.TableResult;
import com.springcloud.travel.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import xyz.fuqufyb.aec.feign.order.OrderFeign;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author fyb
 * @version 1.0
 * @date 2021/3/24 11:14
 */
@RestController
@RequestMapping("/sys/order")
public class SysOrderController {


    @Autowired
    private OrderFeign orderFeign;

    /**
     * @param order
     * @return com.spingcloud.travel.common.JsonResult<com.springcloud.travel.entity.Order>
     * @Author fyb
     * @Description //TODO  新增订单
     * @Date 11:22 2021/3/24
     **/
    @PostMapping("/addOrder")
    public JsonResult<Order> addOrder( Order order) {
        try {
            boolean result = orderFeign.addOrder(order);
            if (result) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return JsonResult.getJsonResultByFail();
    }

    /**
     * @param order
     * @return com.spingcloud.travel.common.JsonResult<com.springcloud.travel.entity.Order>
     * @Author fyb
     * @Description //TODO  修改订单数据
     * @Date 11:22 2021/3/24
     **/
    @PostMapping("/updateOrder")
    public JsonResult<Order> updateOrder( Order order) {
        try {
            boolean result = orderFeign.updateOrder(order);
            if (result) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.getJsonResultByFail();
    }

    /**
     * @param ids
     * @return com.spingcloud.travel.common.JsonResult<com.springcloud.travel.entity.Order>
     * @Author fyb
     * @Description //TODO  批量删除订单
     * @Date 11:22 2021/3/24
     **/
    @PostMapping("/delOrder")
    public JsonResult<Order> delOrder(@RequestParam("ids") String[] ids) {
        try {
            boolean result = orderFeign.delOrder(ids);
            if (result) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.getJsonResultByFail();
    }

    /**
     * @param map
     * @return com.spingcloud.travel.common.TableResult<com.springcloud.travel.entity.Order>
     * @Author fyb
     * @Description //TODO  //获取订单列表
     * @Date 11:18 2021/3/24
     **/
    @GetMapping("/getOrder")
    public TableResult<Order> getHotel(@RequestParam Map<String, String> map) {
        return orderFeign.getOrder(map);
    }
}